package cn.javase.base.io._02_缓冲流;

import java.io.*;

public class _效率测试 {
    public static void main(String[] args) {
        String inputUrl = "D:\\Code\\study\\JavaCode\\JavaSEDemo\\base\\src\\main\\java\\cn\\javase\\base\\io\\_02_缓冲流\\效率测试文本-上林赋.txt";
        String outputUrl = inputUrl.replace("上林赋", "上林赋_copy");
        try(
            FileInputStream fileInputStream = new FileInputStream(inputUrl);
            FileOutputStream fileOutputStream = new FileOutputStream(outputUrl);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream)
        ) {
            /* 使用节点流 */
            long begin = System.currentTimeMillis();
            int readByte;
            while ((readByte = fileInputStream.read()) != -1) {
                fileOutputStream.write(readByte);
            }
            fileOutputStream.flush();
            long end = System.currentTimeMillis();
            System.out.println("使用节点流耗时：" + (end - begin) + "ms");
            /* 使用缓冲流 */
            begin = System.currentTimeMillis();
            while ((readByte = bufferedInputStream.read()) != -1) {
                bufferedOutputStream.write(readByte);
            }
            bufferedOutputStream.flush();
            end = System.currentTimeMillis();
            System.out.println("使用缓冲流耗时：" + (end - begin) + "ms");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
